// 雨量chart
var rainChartOption = {
    chart: {
        zoomType: 'x'
    },
    exporting:{
    	enabled : false
    },
    xAxis: {
        type: 'datetime',
        dateTimeLabelFormats: {
            day: '%m-%d',
            week: '%m-%d',
            month:'%y-%m-%d',
            year:'%y-%m-%d'
        }
    },
    yAxis: [{
        title: {
        	text: '雨量(mm)'
          /*  align:'high',
            offset: 0,
            rotation: 0,
			y: -10*/
        },
    	lineWidth : 1,
    }],
    credits:{
    	enabled:false
    },
    legend: {
        verticalAlign: 'bottom'
    },
    plotOptions:{
    	series:{
    		marker: {
                enabled: false
            }
    	}
    },
    tooltip:{
    	shared: true,
    	crosshairs: true,
    	dateTimeLabelFormats: {
    		second:'%m-%d %H:%M',
    		minute:'%m-%d %H:%M',
    		hour:'%m-%d %H:%M',
            day: '%m-%d',
            week: '%m-%d',
            month:'%y-%m-%d',
            year:'%y-%m-%d'
        }
    }
}

function buildRainChart(windowVals,tabPanel){
	var id = tabPanel.attr('id');
	var bTm = windowVals.startTime;
	var eTm = windowVals.endTime;
	var stcd = tabPanel.data('stcd');
	var callType = tabPanel.data('callType');
	
	var splitBTm = bTm.split('-');
	var startDate = new Date(splitBTm[0],splitBTm[1] - 1,splitBTm[2]);
	var chartParams = {};
	
	if(id == 'day'){
		if(callType == 'rain'){
			chartParams.url = '../gis/RainfallScreen.json?method=getDayProcessByGisJs';
		}else if(callType == 'layerRain'){
			chartParams.url = '../gis/LayerRainfallScreen.json?method=getDayLayerProcessByGisJs';
		}
		chartParams.chartTitle = '日雨量过程线';	
		chartParams.seriesData = [
			{type: 'column',name: '日降雨过程',color : 'green',dataVal : 'rainVals'},
			{type: 'spline',name: '累计降雨曲线',color : '#FF0000',dataVal : 'rainTotVals'}
		];
	}else if(id == 'hour'){
		if(callType == 'rain'){
			chartParams.url = '../gis/RainfallScreen.json?method=getHourProcessByGisJs';
		}else if(callType == 'layerRain'){
			chartParams.url = '../gis/LayerRainfallScreen.json?method=getHourLayerProcessByGisJs';
		}
		chartParams.chartTitle = '时雨量过程线';	
		chartParams.seriesData = [
			{type: 'column',name: '时降雨过程',color : 'green',dataVal : 'rainVals'},
			{type: 'spline',name: '累计降雨曲线',color : '#FF0000',dataVal : 'rainTotVals'}
		];
	}
	chartParams.subChartTitle = bTm + '至' + eTm;
	var sendParams = {bTm:bTm,eTm:eTm,stcd:stcd,r:new Date().getTime()};	
	buildChart2(tabPanel,startDate,rainChartOption,chartParams,sendParams,id);
}

function buildRainTable(windowVals,tabPanel){
	var id = tabPanel.attr('id');
	var stcd = tabPanel.data('stcd');
	var callType = tabPanel.data('callType');
	var startTime = windowVals.startTime;
	var endTime = windowVals.endTime;
	
	var sendParams = {bTm:startTime,eTm:endTime,stcd:stcd,r:new Date().getTime()};
	var params = $.extend({},windowVals);
	params.csvDataHeaders = '序号,日期,降雨量(mm),累计降雨量(mm)';
	params.dataKeys = ['tm','val','totalVal'];
	
	if(id == 'day'){
		params.dataIndex = ['one','three','seven','fifteen','thirty'];
		params.fDataIndex = ['fOne','fThree','fSeven','fFifteen','fThirty'];
		params.sotrHistory=['oneSotrHistory','threeSotrHistory','sevenSotrHistory','fifteenSotrHistory','thirtySotrHistory'];
		params.maxMinAvg=['oneViewDates','threeViewDates','sevenViewDates','fifteenViewDates','thirtyViewDates'];
		params.plMaxDateName =['最大1天降雨','最大3天降雨','最大7天降雨','最大15天降雨','最大30天降雨'];
		
		if(callType == 'rain'){
			params.chartDataTableUrl = '../gis/RainfallScreen.json?method=getDayProcess';
			params.analysisTableUrl = '../gis/RainfallScreen.json?method=getRainSlideDay';
		}else if(callType == 'layerRain'){
			params.chartDataTableUrl = '../gis/LayerRainfallScreen.json?method=getDayLayerProcess';
			params.analysisTableUrl = '../gis/LayerRainfallScreen.json?method=getRainLayerSlideDay';
		}
	}else if(id == 'hour'){
		params.dataIndex = ['oneHour','threeHour','sixHour','twelveHour','twentyFourHour'];
		params.fDataIndex = ['fOne','fThree','fSeven','fFifteen','fThirty'];
		params.sotrHistory=['oneHourSotrHistory','threeHourSotrHistory','sixHourSotrHistory','twelveHourSotrHistory','twentyFourHourSotrHistory'];
		params.maxMinAvg=['oneHourViewDates','threeHourViewDates','sixHourViewDates','twelveHourViewDates','twentyFourHourViewDates'];
		params.plMaxDateName =['最大1小时降雨','最大3小时降雨','最大6小时降雨','最大12小时降雨','最大24小时降雨'];
		
		if(callType == 'rain'){
			params.chartDataTableUrl = '../gis/RainfallScreen.json?method=getHourProcess';
			params.analysisTableUrl = '../gis/RainfallScreen.json?method=getRainSlideHour';
		}else if(callType == 'layerRain'){
			params.chartDataTableUrl = '../gis/LayerRainfallScreen.json?method=getHourLayerProcess';
			params.analysisTableUrl = '../gis/LayerRainfallScreen.json?method=getRainLayerSlideHour';
		}
	}
	buildTable(tabPanel,params,sendParams,id,'rain');
}

function windowRainQuery(event){
	var showTabPanel = event.data.panel;
	var windowVals = getWindowVals(showTabPanel,true,false);
	buildRainChart(windowVals,showTabPanel);
	buildRainTable(windowVals,showTabPanel);
}